package jpm.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.persistence.*;
import static javax.persistence.FetchType.*;
import static javax.persistence.CascadeType.*;

@Entity
public class JSR implements Serializable
{
	@Id
	@Column(name="num")
	private int number;
	private String description;
	@ManyToMany(mappedBy="jsrs")
	private List<Platform> platforms;
	@OneToMany(fetch=EAGER, cascade=ALL)
	private List<Package> packages;
	public JSR () {
	}
	public JSR (int id) {
		setNumber(id);
	}
	public JSR (int id, String description, Package... packages) {
		this(id);
		setDescription(description);
		setPackages(new ArrayList<Package>(Arrays.asList(packages)));
	}
	public int getNumber () {
		return this.number;
	}
	public void setNumber (int number) {
		this.number = number;
	}
	public String getDescription () {
		return description;
	}
	public void setDescription (String description) {
		this.description = description;
	}
	public List<Platform> getPlatforms () {
		return platforms;
	}
	public void setPlatforms (List<Platform> platforms) {
		this.platforms = platforms;
	}
	public List<Package> getPackages () {
		return packages;
	}
	public void setPackages (List<Package> packages) {
		this.packages = packages;
		if (packages != null) for (Package p: packages) p.setJsr(this);
	}
}
